package cordoba.presentation
{
    import cordoba.application.ChangePlanEvent;
    import cordoba.application.ChangeProcessEvent;
    import cordoba.application.ClickProcessEvent;
    import cordoba.domain.Process;
    import cordoba.domain.Processes;
    
    import flash.events.EventDispatcher;

    public class ProcessesListPM extends EventDispatcher
    {

        [Inject]
        [Bindable]
        public var processes:Processes;
        
        [MessageDispatcher]
        public var dispatcher:Function;
        
        
        [MessageHandler]
        public function onChangePlan(event:ChangePlanEvent):void {
            processes.filterBy(event.plan.processes);
        }
		
		public function changeProcess(process:Process):void {
			dispatcher(new ChangeProcessEvent(process));
		}
		public function clickProcess(process:Process):void {
			dispatcher(new ClickProcessEvent(process));
		}

		[MessageHandler]
		public function onClickProcess(event:ClickProcessEvent):void {
			if(event.process.status != Process.STOPPED){
				event.process.status = Process.STOPPED;
			}else{
				event.process.status = Process.INPROGRESS;
			}
		}
    }
}